package cn.xutongxue.interview.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import cn.xutongxue.interview.entity.Question;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionVo implements Serializable {

    private static final long serialVersionUID = 9193176196176671703L;
    private Long id;
    private String title;
    private String content;
    private List<String> tagList;
    private String answer;
    private Long userId;
    private Integer priority;
    private String source;
    private Integer needVip;
    private Integer viewNum;
    private Integer thumbNum;
    private Integer favourNum;
    private Date reviewTime;
    private Date editTime;
    private Date createTime;
    private Date updateTime;

    /**
     * 对象转Vo
     * @param question 对象
     * @return vo
     */
    public static QuestionVo objToVo(Question question) {
        if (question == null) {
            return null;
        }
        QuestionVo questionVO = new QuestionVo();
        BeanUtils.copyProperties(question, questionVO);
        questionVO.setTagList(JSONUtil.toList(JSONUtil.parseArray(question.getTags()), String.class));
        return questionVO;
    }

    public static Question voToObj(QuestionVo questionVo) {
        if (questionVo == null) {
            return null;
        }
        Question question = new Question();
        BeanUtil.copyProperties(questionVo, question);
        List<String> tagList = questionVo.getTagList();
        question.setTags(JSONUtil.toJsonStr(tagList));
        return question;
    }


}
